package mover;

import functions.*;

public class FunctionMover extends GameMover {
	public static final MoveFunction NOTHING = new Constant();
	public static final MoveFunction LINEAR = new Linear();
	public static final MoveFunction SINUS = new Sinus(20, 20);
	public static final MoveFunction SQRT = new Sqrt(10);
	
	private final GameMover mover;
//	public static final MoveFunction TEST = new MoveFunction() {
//		@Override
//		public int getY(int x) {
//			return (int) (20*Math.sin(Math.sin(x/20)) + x);
//		}
//
//		@Override
//		public MoveFunction getInverseFunction() {
//			return null;
//		}
//	};
	
	private MoveFunction func;
	
	public FunctionMover(GameMover mover, MoveFunction func) {
		this.mover = mover;
		this.func = func;
	}
	
	public FunctionMover(MoveFunction func) {
		this(null, func);
	}

	@Override
	public void move(int counter) {
		if(mover != null)
			mover.move(counter);
		
		//timersaver
//		if(xMove == 0 && yMove == 0) return;
		
		if(xMove != 0 && counter%xMove == 0) {
			xPos = (int) ((signum(xMove) * func.getNextY()) * xMult);
		}
	}

	@Override
	public void reset() {
		super.reset();
		func.reset();
	}

	@Override
	public FunctionMover clone() throws CloneNotSupportedException {
		FunctionMover clone = new FunctionMover(this.func.clone());
		this.clone_help(clone);
		
		return clone;
	}

}
